import React, { useEffect } from 'react';
import { append } from '../utils';

function map() {
  const obj = {};
  // eslint-disable-next-line dot-notation
  obj[true] = 'value';
  obj[123] = 'value';
  obj[{ a: 1 }] = 'value';

  append(Object.keys(obj));
  append(obj['[object Object]']);

  append('---------------------');

  // 使用 map 代替
  const m = new Map();
  const tom = { name: 'tom' };

  m.set(tom, 90);

  append(typeof m);
  append(JSON.stringify(m));
  append(m.get(tom));

  m.forEach((value, key) => {
    append(`${JSON.stringify(key)}: ${value}`);
  });
}

export default function Async() {
  useEffect(map, null);

  return (
    <div id="content">
      <p>map</p>
    </div>
  );
}
